package com.patsnap.one.etl.mybaties.injector;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.extension.injector.methods.InsertBatchSomeColumn;
import com.github.jeffreyning.mybatisplus.base.MppSqlInjector;
import com.patsnap.one.etl.mybaties.injector.methods.UpsertBatchSomeColumn;

import java.util.List;

public class BatchSqlInjector extends MppSqlInjector {
    @Override
    public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
        List<AbstractMethod> methodList = super.getMethodList(mapperClass, tableInfo);
        // 标记INSERT_UPDATE和INSERT的字段，在对应的场景下，会忽略对应的字段，不会插入值，使用数据库默认值
        // NOTE：无法应用于@TableId字段
        methodList.add(new InsertBatchSomeColumn(i -> i.getFieldFill() != FieldFill.INSERT_UPDATE && i.getFieldFill() != FieldFill.INSERT));
        methodList.add(new UpsertBatchSomeColumn(i -> i.getInsertStrategy() != FieldStrategy.NEVER && i.getUpdateStrategy() != FieldStrategy.NEVER));
        return methodList;
    }
}
